// 获取给定月份的最后一天
function getMonthMaxDay(year, month) {
	var maxDay = 31;
	if (month == 2) {
		maxDay = 28;
		if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
			maxDay = 29;
		}
	} else if (month == 4 || month == 6 || month == 9 || month == 11) {
		maxDay = 30;
	}
	return maxDay;
}
// 获取给定月份的上个月的最后一天
function getLastMonthMaxDay(year, month) {
	if (month == 1) {
		month = 12;
		year -= 1;
	} else {
		month -= 1;
	}
	var maxDay = getMonthMaxDay(year, month);
	return maxDay;
}
// 获取给定日期是周几:周日是0,周一时0周六是6
function getWeekIndex(dayStr) {
	var arr = dayStr.split("-");
	var year = parseInt(arr[0]);
	var month = parseInt(arr[1]) - 1;
	var day = parseInt(arr[2]);
	var originDate = new Date(year, month, day);
	return originDate.getDay()
}
// 给定日期转换成字典形式
function getYMDWithStr(dayStr) {
	var arr = dayStr.split("-");
	var year = parseInt(arr[0]);
	var month = parseInt(arr[1]);
	var day = 1;
	if (arr[2]) {
		day = parseInt(arr[2]);
	}
	return {
		'year': year,
		'month': month,
		'day': day
	};
}
// 获取给定月份的上个月的字典形式
function getLastYMDict(year, month) {
	if (month == 1) {
		month = 12;
		year -= 1;
	} else {
		month -= 1;
	}
	return {
		'year': year,
		'month': month
	};
}
// 获取给定月份的下个月的字典形式
function getNextYMDict(year, month) {
	if (month == 12) {
		month = 1;
		year += 1;
	} else {
		month += 1;
	}
	return {
		'year': year,
		'month': month
	};
}
// 年月转换成2021-09这种形式
function outYMStr(year, month) {
	var monthStr = month + '';
	if (month < 10) {
		monthStr = '0' + month;
	}
	return year + '-' + monthStr;
}
// 年月转换成2021年09月
function outChinaYMStr(year, month) {
	var monthStr = month + '';
	if (month < 10) {
		monthStr = '0' + month;
	}
	return year + '年' + monthStr + '月';
}
// 年月转换成21年09月
function outChinaYMStr2(year, month) {
	var str = outChinaYMStr(year, month)
	return str.substring(2,str.length)
}
// 获取给定日期的下一天
function getNextDay(dayStr) {
	var sarr = dayStr.split("-");
	var syear = parseInt(sarr[0]);
	var smonth = parseInt(sarr[1]) - 1;
	var sday = parseInt(sarr[2]);
	var sdate = new Date(syear, smonth, sday, 0, 0, 0);
	var daytime = sdate.getTime() + 1000 * 60 * 60 * 25;
	var newDate = new Date(daytime);
	var cyear = newDate.getFullYear();
	var cmonth = newDate.getMonth() + 1;
	var cday = newDate.getDate();
	var thisDay = cyear + "-";
	if (cmonth < 10) {
		thisDay += "0";
	}
	thisDay += cmonth + "-";
	if (cday < 10) {
		thisDay += "0";
	}
	thisDay += cday;
	return thisDay;
}
//获取设备时间
function getCurrentDeviceDay(){
	var newDate = new Date();
	var cyear = newDate.getFullYear();
	var cmonth = newDate.getMonth() + 1;
	var cday = newDate.getDate();
	var thisDay = cyear + "-";
	if (cmonth < 10) {
		thisDay += "0";
	}
	thisDay += cmonth + "-";
	if (cday < 10) {
		thisDay += "0";
	}
	thisDay += cday;
	return thisDay;
}

function getLastWeekStartDate(ymdStr){
	var currentDate = ymdStr.split("-");
	var cyear = parseInt(currentDate[0]);
	var cmonth = parseInt(currentDate[1]);
	var cday = parseInt(currentDate[2]);
	cday -= 7;
	if(cday < 1) {
		cmonth = cmonth - 1;
		if(cmonth == 0) {
			cyear -= 1;
			cmonth = 12;
		}
		var maxDay = getMonthMaxDay(cyear,cmonth);
		cday = maxDay + cday;
	}
	var descStr = cyear + "-";
	if (cmonth < 10) {
		descStr += "0";
	}
	descStr += cmonth + "-";
	if (cday < 10) {
		descStr += "0";
	}
	descStr += cday
	return descStr;
}
// srcDay日期:例如2020-01-01 intervalDay间隔天数例如7 返回2020-01-08
//不能超过28天
//获取指定日志之后指定天数的日期
function getDaysAfterInterval(srcDay,intervalDay){
	var srcArr = srcDay.split("-");
	var cyear = parseInt(srcArr[0]);
	var cmonth = parseInt(srcArr[1]);
	var cday = parseInt(srcArr[2]);
	var cMaxDay = getMonthMaxDay(cyear,cmonth);
	cday += intervalDay;
	if(cday < 1) {
		cmonth = cmonth - 1;
		if(cmonth == 0) {
			cyear -= 1;
			cmonth = 12;
		}
		var maxDay = getMonthMaxDay(cyear,cmonth);
		cday = maxDay + cday;
	}else if (cMaxDay < cday) {
		cmonth = cmonth + 1;
		if(cmonth == 12) {
			cyear += 1;
			cmonth = 1;
		}
		cday = cday - maxDay
	}
	var descStr = cyear + "-";
	if (cmonth < 10) {
		descStr += "0";
	}
	descStr += cmonth + "-";
	if (cday < 10) {
		descStr += "0";
	}
	descStr += cday
	return descStr;
}

// dayStr开始日期,intervals间隔天数
function isDateOverdue(srcDay,intervals,today){
	intervals = parseInt(intervals)
	if (isNaN(intervals)) {
		return false
	}
	var destday = getDaysAfterInterval(srcDay,intervals)
	if (today > destday) {
		return true;
	}
	return false
}

function getDeviceDateStr(){
	var currentDate = new Date();
	var cyear = currentDate.getFullYear();
	var cmonth = currentDate.getMonth() + 1;
	var cday = currentDate.getDate();
	var thisDay = cyear + "-" 
	if (cmonth < 10) {
		thisDay +='0'
	}
	thisDay+= cmonth + "-" 
	if (cday < 10) {
		thisDay +='0'
	}
	thisDay += cday;
	return thisDay;
}
function getDeviceYearMonthStr(){
	var currentDate = new Date();
	var cyear = currentDate.getFullYear();
	var cmonth = currentDate.getMonth() + 1;
	var cday = currentDate.getDate();
	var thisDay = cyear + "-" 
	if (cmonth < 10) {
		thisDay +='0'
	}
	thisDay+= cmonth
	return thisDay;
}

function changeDateToString(dateObj){
	var dateStr = dateObj.getFullYear()+'-'
	if (dateObj.getMonth() < 9) {
		dateStr += '0'
	}
	dateStr += (dateObj.getMonth() + 1)+'-'
	if (dateObj.getDate() < 10) {
		dateStr += '0'
	}
	dateStr += dateObj.getDate()
	return dateStr
}
function changeTimeToString(dateObj){
	var dateStr = dateObj.getHours()
	if (dateObj.getHours() < 9) {
		dateStr = '0'+dateStr
	}
	dateStr += ':'
	if (dateObj.getMinutes() < 10) {
		dateStr += '0'
	}
	dateStr += dateObj.getMinutes()
	return dateStr
}